package utils

import (
	"database/sql/driver"
	"errors"
	"fmt"
	"time"
)

type MyTime struct {
	time.Time
}

var tf = "2006-01-02 15:04:05"

func (t MyTime) MarshalJSON() ([]byte, error) {
	output := fmt.Sprintf("\"%s\"", t.Format(tf))
	return []byte(output), nil
}
func (t MyTime) Value() (driver.Value, error) {
	return t.Time.Format(tf), nil
}
func (t *MyTime) Scan(value interface{}) error {
	v, isOk := value.(time.Time)
	if isOk {
		t.Time = v
		return nil
	}
	return errors.New("无法转换成时间类型。")
}
